﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Agnes.Core;

namespace Agnes.MyDocsLib
{
    internal static class DocumentPanelsHelper
    {
        public static bool ActiveView(IDocumentPanel view)
        {
            foreach (IDocumentPanel i in AgnesServiceManager.AgnesWorkBenchService.DocumentPanels)
            {
                if (i.Content == view)
                {
                    AgnesServiceManager.AgnesWorkBenchService.FocusedDocumentPanel = view;
                    return true;
                }
            }

            return false;
        }

        public static IDocumentPanel GetDocumentByModel(Article article)
        {
            foreach (IDocumentPanel i in AgnesServiceManager.AgnesWorkBenchService.DocumentPanels)
            {
                if (i.Content is ArticleView)
                {
                    ArticleViewModel vm = (i.Content as ArticleView).DataContext as ArticleViewModel;
                    if (vm != null)
                    {
                        if (vm.Model.Id == article.Id)
                        {
                            return i;
                        }
                    }
                }
            }

            return null;
        }
    }
}
